import { _decorator, Component, sys } from 'cc';
import { Constant } from './Constant';
const { ccclass, property } = _decorator;

@ccclass('StorageManager')
export default class StorageManager extends Component {

    public jsonData: { [key: string]: any } = {};

    public static ClearData() {
        sys.localStorage.clear();
    }

    public static GetItem(key: string) {
        return sys.localStorage.getItem(key);
    }

    public static SetItem(key: string, value: any) {
        sys.localStorage.setItem(key, value.toString());
    }

    public static GetBool(key: string) {
        return Boolean(sys.localStorage.getItem(`${key}`));
    }

    public static SetBool(key: string, value: boolean) {
        sys.localStorage.setItem(key, Number(value).toString());
    }

    public static GetCount(key: string) {
        let count = 0;
        if (StorageManager.GetItem(key) && Number(sys.localStorage.getItem(key))) {
            count = Number(sys.localStorage.getItem(key));
        }

        return count;
    }

}
